﻿using MediatR;
using Traceability.Commont.Domains.BatchManagementFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.ReturnWeighing
{
    public class ReturnWeighingUpdateHandlercscs : IRequestHandler<ReturnWeighingUpdateCommond, Resqults>
    {
        private readonly IBateRepository<Byproduct> _Byproduct;

        public ReturnWeighingUpdateHandlercscs(IBateRepository<Byproduct> byproduct)
        {
            _Byproduct = byproduct;
        }

        public async Task<Resqults> Handle(ReturnWeighingUpdateCommond request, CancellationToken cancellationToken)
        {

            var list = new Resqults() {Code=0 };


            var res = _Byproduct.GetAll().Where(x => x.ByproductId == request.ByproductId).FirstOrDefault();


            if(res!=null)
            {
               res.DocumentsNo=request.DocumentsNo;
                res.ByproductDate=request.ByproductDate;
                res.ShoppingType=request.ShoppingType;
                res.byproductNum = request.byproductNum;
                res.byproductNoteWeight = request.byproductNoteWeight;
                res.byproductNoteTare=request.byproductNoteTare;
                res.byproductNetWeight = request.byproductNetWeight;
                res.Rremark=request.Rremark;



             var querysuccess=   _Byproduct.Update(res);

                if(querysuccess!=null)
                {
                    list.Code = 1;
                }
            }


            return list;

        }
    }
}
